/**
 * Created by wang on 18/3/7.
 */
$(function(){


    $('.video_area>a').each(function(){
        var url = $(":input",$(this)).val();
        var text = $("span",$(this)).text();

        $(this).click(function(){

            layer.open({
                type: 2,
                title: text,
                shadeClose: true,
                shade: 0.8,
                area: ['60%', '90%'],
                content: url //iframe的url
            });
        });
    });

    var liWidth=$("#labelUl li").width();
    $(".label").css("width",liWidth);
//        $("#label0").css('width',liWidth+(170));
    $('[id^="labelSpan"]').each(function(i,n){
        var temp = $(this).width();
        $(this).css("padding-left",(liWidth-temp)/2);

        var width = 0;
        for(var a=0;((a-i)!=0);a++){
            width+=$("#label"+a).width();
        }
        $(this).parent().css("left",width);
    });

    var text = $('#recommendName').val();

    var rootPath = $('#rootPath').val();

    var url = rootPath + '/cms?dataId='+$('#fromId').val()+'&navType='+$('#recommendType').val();

    if(text){
        /*layer.open({
         type: 2,
         title: false,
         closeBtn: 1, //不显示关闭按钮
         shade: [0],
         area: ['340px', '215px'],
         offset: 'rb', //右下角弹出
         time: 2000, //2秒后自动关闭
         anim: 2,
         content: ['page/building.html', 'no'], //iframe的url，no代表不显示滚动条
         end: function(){ //此处用于演示
         layer.open({
         type: 2,
         title: false,
         shadeClose: true,
         shade: false,
         time: 5000,
         area: ['950px', '630px'],
         content: url
         });
         }
         });*/

        //iframe的url，no代表不显示滚动条
        //1920*1080   1600*770
        var myWidth = window.screen.availWidth;
        var myHeight = 828;
        var offset = $('.flicker-example').offset().top - 20;
        var myOffset = [offset+"px",0];
        if(isMobile()){
            myWidth = 1440;
            myOffset = [offset+"px","46px"];
        }
        var height,width;
        var hTemp = parseInt(accMul(accDiv(870,1240),myHeight));
        var wTemp = parseInt(accMul(accDiv(420,600),myWidth));


        height = hTemp+"px";
        width = wTemp+"px";
        $.ajax({
            url: url,
            type: 'GET',
            complete: function(response) {
                if (response.status == 200) {
                    layer.open({
                        type: 2,
                        title: false,
                        shadeClose: true,
                        closeBtn:0,
                        shade: false,
                        time: 5000,
                        anim: 2,
                        offset: myOffset,
                        area: [width,height],
                        content: [url, 'no']
                        // end: function() {
                        //     layer.open({
                        //         type: 2,
                        //         title: $('#recommendName').val(),
                        //         closeBtn: 1, //关闭按钮
                        //         shade: [0],
                        //         area: ['340px', '215px'],
                        //         offset: 'rb', //右下角弹出
                        //         time: 5000, //2秒后自动关闭
                        //         anim: 2,
                        //         content: ''
                        //     });
                        // }

                    });

                }
            }});


    }

    function isMobile() {
        var userAgentInfo = navigator.userAgent;

        var mobileAgents = [ "Android", "iPhone", "SymbianOS", "Windows Phone", "iPad","iPod"];

        var mobile_flag = false;

        //根据userAgent判断是否是手机
        for (var v = 0; v < mobileAgents.length; v++) {
            if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
                mobile_flag = true;
                break;
            }
        }

        var screen_width = window.screen.width;
        var screen_height = window.screen.height;

        //根据屏幕分辨率判断是否是手机
        if(screen_width < 500 && screen_height < 800){
            mobile_flag = true;
        }

        return mobile_flag;
    }


});